{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3631c2f8",
   "metadata": {},
   "source": [
    "### 背景介绍：\n",
    "\n",
    "- 输入数据1：人工构造-user表.xlsx，人工构造\n",
    "- 输入数据2：人工构造-movie表.xlsx，人工构造\n",
    "- 目标输出：（人ID、电影ID、评分）表，自动生成\n",
    "- 需要考虑几点：1、有些人不参与评分；2、有些电影不被评分；3、评分数值需要围绕电影评分作为平均值；4、每个人随机挑选几个电影评分；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "450ccb90",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1776d7d8",
   "metadata": {},
   "source": [
    "### 用户表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a86d256f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>是否不评分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>宋江</td>\n",
       "      <td>男</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>扈三娘</td>\n",
       "      <td>女</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>孙二娘</td>\n",
       "      <td>女</td>\n",
       "      <td>是</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>武松</td>\n",
       "      <td>男</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>鲁智深</td>\n",
       "      <td>男</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>李逵</td>\n",
       "      <td>男</td>\n",
       "      <td>是</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>顾大嫂</td>\n",
       "      <td>女</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id name gender 是否不评分\n",
       "0   1   宋江      男     否\n",
       "1   2  扈三娘      女     否\n",
       "2   3  孙二娘      女     是\n",
       "3   4   武松      男     否\n",
       "4   5  鲁智深      男     否\n",
       "5   6   李逵      男     是\n",
       "6   7  顾大嫂      女     否"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_user = pd.read_excel(\"人工构造-user表.xlsx\")\n",
    "df_user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "b463b1fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>宋江</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>扈三娘</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>武松</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>鲁智深</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>顾大嫂</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id name gender\n",
       "0   1   宋江      男\n",
       "1   2  扈三娘      女\n",
       "3   4   武松      男\n",
       "4   5  鲁智深      男\n",
       "6   7  顾大嫂      女"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_user_forrate = df_user.query(\"是否不评分 == '否'\").drop(columns=[\"是否不评分\"])\n",
    "df_user_forrate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68886dbc",
   "metadata": {},
   "source": [
    "### 电影表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "54f0648a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>pubyear</th>\n",
       "      <th>category</th>\n",
       "      <th>豆瓣评分</th>\n",
       "      <th>是否不评分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>功夫熊猫</td>\n",
       "      <td>2008</td>\n",
       "      <td>动画片</td>\n",
       "      <td>8.2</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>唐伯虎点秋香</td>\n",
       "      <td>1993</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>8.7</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>1997</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>9.4</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>武状元苏乞儿</td>\n",
       "      <td>1992</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>8.2</td>\n",
       "      <td>是</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>盗梦空间</td>\n",
       "      <td>2010</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>9.4</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>超体</td>\n",
       "      <td>2014</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>7.4</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>阿凡达</td>\n",
       "      <td>2009</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>8.8</td>\n",
       "      <td>是</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>疯狂动物城</td>\n",
       "      <td>2016</td>\n",
       "      <td>动画片</td>\n",
       "      <td>9.2</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>魂断蓝桥</td>\n",
       "      <td>1940</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>8.8</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>千与千寻</td>\n",
       "      <td>2001</td>\n",
       "      <td>动画片</td>\n",
       "      <td>9.4</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>西虹市首富</td>\n",
       "      <td>2018</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>6.6</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>黑客帝国</td>\n",
       "      <td>1999</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>9.1</td>\n",
       "      <td>是</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>美女与野兽</td>\n",
       "      <td>1991</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>8.5</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>神偷奶爸</td>\n",
       "      <td>2010</td>\n",
       "      <td>动画片</td>\n",
       "      <td>8.6</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>逃学威龙</td>\n",
       "      <td>1991</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>8.1</td>\n",
       "      <td>否</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   title  pubyear category  豆瓣评分 是否不评分\n",
       "0    1    功夫熊猫     2008      动画片   8.2     否\n",
       "1    2  唐伯虎点秋香     1993      喜剧片   8.7     否\n",
       "2    3   泰坦尼克号     1997      爱情片   9.4     否\n",
       "3    4  武状元苏乞儿     1992      喜剧片   8.2     是\n",
       "4    5    盗梦空间     2010      科幻片   9.4     否\n",
       "5    6      超体     2014      科幻片   7.4     否\n",
       "6    7     阿凡达     2009      科幻片   8.8     是\n",
       "7    8   疯狂动物城     2016      动画片   9.2     否\n",
       "8    9    魂断蓝桥     1940      爱情片   8.8     否\n",
       "9   10    千与千寻     2001      动画片   9.4     否\n",
       "10  11   西虹市首富     2018      喜剧片   6.6     否\n",
       "11  12    黑客帝国     1999      科幻片   9.1     是\n",
       "12  13   美女与野兽     1991      爱情片   8.5     否\n",
       "13  14    神偷奶爸     2010      动画片   8.6     否\n",
       "14  15    逃学威龙     1991      喜剧片   8.1     否"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_movie = pd.read_excel(\"人工构造-movie表.xlsx\")\n",
    "df_movie"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "d94ed7f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>pubyear</th>\n",
       "      <th>category</th>\n",
       "      <th>豆瓣评分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>功夫熊猫</td>\n",
       "      <td>2008</td>\n",
       "      <td>动画片</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>唐伯虎点秋香</td>\n",
       "      <td>1993</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>泰坦尼克号</td>\n",
       "      <td>1997</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>盗梦空间</td>\n",
       "      <td>2010</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>超体</td>\n",
       "      <td>2014</td>\n",
       "      <td>科幻片</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>疯狂动物城</td>\n",
       "      <td>2016</td>\n",
       "      <td>动画片</td>\n",
       "      <td>9.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>魂断蓝桥</td>\n",
       "      <td>1940</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>8.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>千与千寻</td>\n",
       "      <td>2001</td>\n",
       "      <td>动画片</td>\n",
       "      <td>9.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>西虹市首富</td>\n",
       "      <td>2018</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>6.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>美女与野兽</td>\n",
       "      <td>1991</td>\n",
       "      <td>爱情片</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>神偷奶爸</td>\n",
       "      <td>2010</td>\n",
       "      <td>动画片</td>\n",
       "      <td>8.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>逃学威龙</td>\n",
       "      <td>1991</td>\n",
       "      <td>喜剧片</td>\n",
       "      <td>8.1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   title  pubyear category  豆瓣评分\n",
       "0    1    功夫熊猫     2008      动画片   8.2\n",
       "1    2  唐伯虎点秋香     1993      喜剧片   8.7\n",
       "2    3   泰坦尼克号     1997      爱情片   9.4\n",
       "4    5    盗梦空间     2010      科幻片   9.4\n",
       "5    6      超体     2014      科幻片   7.4\n",
       "7    8   疯狂动物城     2016      动画片   9.2\n",
       "8    9    魂断蓝桥     1940      爱情片   8.8\n",
       "9   10    千与千寻     2001      动画片   9.4\n",
       "10  11   西虹市首富     2018      喜剧片   6.6\n",
       "12  13   美女与野兽     1991      爱情片   8.5\n",
       "13  14    神偷奶爸     2010      动画片   8.6\n",
       "14  15    逃学威龙     1991      喜剧片   8.1"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_movie_forrate = df_movie.query(\"是否不评分 == '否'\").drop(columns=[\"是否不评分\"])\n",
    "df_movie_forrate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e38e45c3",
   "metadata": {},
   "source": [
    "### 生成评分表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "61380d14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 电影数量\n",
    "total_movie_forrate = len(df_movie_forrate)\n",
    "total_movie_forrate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "5050c823",
   "metadata": {},
   "outputs": [],
   "source": [
    "ratings_data = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "69df0eb3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "dfd940d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d2e24b41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 5 9.8 9.4\n",
      "1 14 8.4 8.6\n",
      "1 10 9.0 9.4\n",
      "1 11 6.5 6.6\n",
      "1 13 9.1 8.5\n",
      "1 2 9.0 8.7\n",
      "1 6 7.4 7.4\n",
      "1 3 8.5 9.4\n",
      "1 15 6.8 8.1\n",
      "\n",
      "2 10 10.3 9.4\n",
      "2 1 7.9 8.2\n",
      "2 6 6.8 7.4\n",
      "2 9 6.6 8.8\n",
      "2 13 7.8 8.5\n",
      "2 5 9.9 9.4\n",
      "2 14 8.0 8.6\n",
      "2 15 8.4 8.1\n",
      "\n",
      "4 5 8.7 9.4\n",
      "4 6 7.3 7.4\n",
      "4 15 8.1 8.1\n",
      "\n",
      "5 9 9.6 8.8\n",
      "5 6 7.4 7.4\n",
      "5 11 6.2 6.6\n",
      "5 14 8.5 8.6\n",
      "5 10 9.2 9.4\n",
      "5 1 7.0 8.2\n",
      "5 2 8.7 8.7\n",
      "5 13 7.8 8.5\n",
      "5 3 9.1 9.4\n",
      "5 8 9.7 9.2\n",
      "5 5 10.3 9.4\n",
      "\n",
      "7 15 8.1 8.1\n",
      "7 3 9.9 9.4\n",
      "7 9 8.4 8.8\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for idx_user, user in df_user_forrate.iterrows():\n",
    "    # 评分数目\n",
    "    rating_cnt = random.randint(3, total_movie_forrate)\n",
    "    # 待评分的电影\n",
    "    user_movie = df_movie_forrate.sample(rating_cnt)\n",
    "    user_id = user[\"id\"]\n",
    "    for idx_movie, movie in user_movie.iterrows():\n",
    "        movie_id = movie[\"id\"]\n",
    "        ratings = movie[\"豆瓣评分\"]\n",
    "        # 正态分布的评分采样\n",
    "        new_ratings = round(np.random.normal(ratings, 0.8), 1)\n",
    "        print(user_id, movie_id, new_ratings, ratings)\n",
    "        ratings_data.append(\n",
    "            [user_id, movie_id, new_ratings]\n",
    "        )\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "65a79ce2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1, 5, 9.8],\n",
       " [1, 14, 8.4],\n",
       " [1, 10, 9.0],\n",
       " [1, 11, 6.5],\n",
       " [1, 13, 9.1],\n",
       " [1, 2, 9.0],\n",
       " [1, 6, 7.4],\n",
       " [1, 3, 8.5],\n",
       " [1, 15, 6.8],\n",
       " [2, 10, 10.3],\n",
       " [2, 1, 7.9],\n",
       " [2, 6, 6.8],\n",
       " [2, 9, 6.6],\n",
       " [2, 13, 7.8],\n",
       " [2, 5, 9.9],\n",
       " [2, 14, 8.0],\n",
       " [2, 15, 8.4],\n",
       " [4, 5, 8.7],\n",
       " [4, 6, 7.3],\n",
       " [4, 15, 8.1],\n",
       " [5, 9, 9.6],\n",
       " [5, 6, 7.4],\n",
       " [5, 11, 6.2],\n",
       " [5, 14, 8.5],\n",
       " [5, 10, 9.2],\n",
       " [5, 1, 7.0],\n",
       " [5, 2, 8.7],\n",
       " [5, 13, 7.8],\n",
       " [5, 3, 9.1],\n",
       " [5, 8, 9.7],\n",
       " [5, 5, 10.3],\n",
       " [7, 15, 8.1],\n",
       " [7, 3, 9.9],\n",
       " [7, 9, 8.4]]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratings_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "93acbe91",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ratings_data = pd.DataFrame(\n",
    "    ratings_data, columns=[\"user_id\", \"movie_id\", \"rating\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "1adf4929",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>movie_id</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>9.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>6.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>13</td>\n",
       "      <td>9.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>15</td>\n",
       "      <td>6.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2</td>\n",
       "      <td>10</td>\n",
       "      <td>10.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>7.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>6.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>6.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>7.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>9.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2</td>\n",
       "      <td>15</td>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>7.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>4</td>\n",
       "      <td>15</td>\n",
       "      <td>8.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "      <td>6.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>5</td>\n",
       "      <td>14</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>9.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>5</td>\n",
       "      <td>13</td>\n",
       "      <td>7.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>9.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>9.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>10.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>7</td>\n",
       "      <td>15</td>\n",
       "      <td>8.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>9.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    user_id  movie_id  rating\n",
       "0         1         5     9.8\n",
       "1         1        14     8.4\n",
       "2         1        10     9.0\n",
       "3         1        11     6.5\n",
       "4         1        13     9.1\n",
       "5         1         2     9.0\n",
       "6         1         6     7.4\n",
       "7         1         3     8.5\n",
       "8         1        15     6.8\n",
       "9         2        10    10.3\n",
       "10        2         1     7.9\n",
       "11        2         6     6.8\n",
       "12        2         9     6.6\n",
       "13        2        13     7.8\n",
       "14        2         5     9.9\n",
       "15        2        14     8.0\n",
       "16        2        15     8.4\n",
       "17        4         5     8.7\n",
       "18        4         6     7.3\n",
       "19        4        15     8.1\n",
       "20        5         9     9.6\n",
       "21        5         6     7.4\n",
       "22        5        11     6.2\n",
       "23        5        14     8.5\n",
       "24        5        10     9.2\n",
       "25        5         1     7.0\n",
       "26        5         2     8.7\n",
       "27        5        13     7.8\n",
       "28        5         3     9.1\n",
       "29        5         8     9.7\n",
       "30        5         5    10.3\n",
       "31        7        15     8.1\n",
       "32        7         3     9.9\n",
       "33        7         9     8.4"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ratings_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "5930e5eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ratings_data.to_excel(\"自动生成-评分数据.xlsx\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04eddb2a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
